SharePoint Learning Kit Customization
SLK Queries and Query Sets

The SharePoint Learning Kit query and query set features allow you to use XML to customize the simple tabular reports that display in the SLK Assignment List Web Part. This section explains how.

If you're a programmer, you can also access SLK query and query set functionality from within your own programs—a later section explains how.

SLK Queries in Assignment List Web Part

The right pane in the SharePoint Learning Kit's Assignment List Web Part displays the results of a query selected in the left pane:

These queries are defined within the SLK Settings file, a customizable configuration file. For example, the SLK Settings file excerpt below on the left products Assignment List Web Part output such as that shown on the right.

XML
<Query
Name="GradedLearnerAssignments"
Title="Graded Assignments"
ViewName="LearnerAssignmentListForLearners"
CountViewColumnName="LearnerAssignmentId">
<Column
Title="Assignment"
RenderAs="Link"
ViewColumnName="AssignmentTitle"
ViewColumnName2="LearnerAssignmentId"
NullDisplayString="Untitled" />
<Condition
ViewColumnName="IsFinal"
Operator="Equal"
Value="1" />
<Sort
ViewColumnName="AssignmentTitle"
Ascending="true" />
</Query>

(Note that in the query above, "ascending" is the default sort, but the screen shot above reflects the display after the user clicked on the "Assignment" column header to re-sort in a descending order.)

LearningStore Views

The example above contains the attribute assignment ViewName="LearnerAssignmentListForLearners". "LearnerAssignmentListForLearners" is a LearningStore view defined by SLK. In order to understand how SLK queries work, you need to understand LearningStore views. (LearningStore is a database access component, part of Microsoft Learning Components, explained later in this documentation set.)

One example of a LearningStore view is LearnerAssignmentListForLearners, which you can think of as a "virtual table" containing approximately 40 columns, and one row for each assignment for which the current user is a learner.

If you're familiar with Microsoft SQL Server, it may help to think of a LearningStore view as a "join" across multiple tables. (That's basically how it's implemented.) In the case of LearnerAssignmentListForLearners, this join includes over half a dozen tables, retrieving many pieces of information related to learner assignments that are accessible by a learner (hence the name of the view).

Each LearningStore view contains security rules that determine what information can be returned in a query using that view. Disallowed rows (for example, other learner's assignments) and columns (such as assignment grade, before grading is completed) are automatically excluded.

A SLK query pulls a subset of rows and columns from a given LearningStore view. In the example above:

In the general case, a SLK query can include any number of <Column>, <Condition>, and <Sort> elements. Multiple conditions are "AND-ed" together.

For detailed information about how to construct SLK queries, see SLK Settings. For more information about LearningStore views, see SLK+MLC Schema.

Non-Assignment Queries

Assignment List Web Part is optimized for viewing assignments, but it can be used to display other information as well. Here's an example that displays the SLK identifiers and names of all users that SLK is aware of:

XML
<Query
Name="Users"
Title="All Users"
ViewName="UserItem">
<Column
Title="ID"
ViewColumnName="Id"/>
<Column
Title="Name"
ViewColumnName="Name"/>
<Sort
ViewColumnName="Name"
Ascending="true" />
</Query>
LearningStore Security

Consider the preceding example, the "Users" query. If you added the query above to your Web site's SLK Settings, you'd get an "access denied" message when you tried to access the query using Assignment List Web Part, because the default security rules for the "UserItem" view (actually a table in the SLK database, as described in a later section) don't permit anyone to access this table (except under elevated privileges). This is consistent with the "secure by default" philosophy of Microsoft Learning Components.

You can modify the SLK database schema to change these rules. For example you could insert the following XML into SlkSchema.xml, run "SchemaCompiler.exe SlkSchema.xml /OutputUpgrade SlkUpgrade.sql" (SchemaCompiler.exe is a console application available in the SLK SDK), and then update the SLK database using a command line such as "sqlcmd -d SharePointLearningKit -i SlkUpgrade.sql" (sqlcmd.exe is a SQL Server console application tool).

XML
<ExtendItemType Name="UserItem">
<GrantQueryRight>
<Expression>1</Expression>
</GrantQueryRight>
</ExtendItemType>

After resetting IIS (iisreset.exe), the new security rule above will take effect, and the "Users" query above will show a list of all users know to SLK. Of course, this security rule isn't particularly secure—the condition for granting a user permission to execute the query is 1 (i.e. "always")—but in the general case this expression could be an arbitrary SQL expression that takes into account the role(s) of the current user.

See the SLK+MLC Schema section for more information about customizing security in SLK.

SLK Query Sets

A SLK query set is simply an ordered set of SLK queries. The left pane in SLK's Assignment List Web Part is defined by a query set, similar to the following:

As with SLK queries, SLK query sets are defined in the SLK Settings file. Assignment List Web Part allows the Web site designer to choose a query set to display. Alternatively, the query set can be chosen automatically based on the user's roles (learner, instructor, or both) on that Web site.

Here's an example of a query set definition:

XML
<QuerySet
Name="LearnerQuerySet"
Title="Learner Query Set"
DefaultQueryName="DueTodayLearner">
<IncludeQuery
QueryName="OverdueLearner"/>
<IncludeQuery
QueryName="DueTodayLearner"/>
<IncludeQuery
QueryName="DueThisWeekLearner"/>
<IncludeQuery
QueryName="DueNextWeekLearner"/>
<IncludeQuery
QueryName="ReturnedLearner"/>
</QuerySet>

A <QuerySet> XML element defines a single query set. Each nested <IncludeQuery> XML element specifies a SLK query to include in the query set. Note that the display name of each query (such as "Due Today" in the example above) comes from the definition of the query, not the <IncludeQuery> XML element.

For detailed information about how to construct SLK query sets, see SLK Settings.

Default Queries

The SLK Settings file that's supplied with SharePoint Learning Kit contains the following queries. The query names shown in bold are the internal query names that are used to refer to a query from within a query set definition or within code that calls the SLK API.

For more information (for example, what columns are included in each of these queries), see the default SlkSettings.xml, or download your Web site's current SLK Settings XML file from the SLK Configuration page in SharePoint Central Administration. See SLK Settings to learn how to interpret a SLK Settings file, and how to modify it or create a new one.

Default Query Sets
The default SLK Settings file that's supplied with SharePoint Learning Kit contains the following query sets:
For More Information
SLK Concepts
SLK Settings
Default SLK Settings XML
SLK+MLC Schema
SLK API Overview
SlkSettings Class (SLK API)
Next Topic: SLK+MLC Schema